<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#assign css>
    <link rel="stylesheet" href="/assets/vendor/zTree/css/zTreeStyle/zTreeStyle.css"/>

</#assign>
<#assign js>
    <script src="/assets/vendor/zTree/js/jquery.ztree.all.min.js"></script>

    <script>
        $(".btn-submit").click(function () {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/agentUser/grant/${user.userId}",
                data: $(".form-grant").serialize(),
                success: function (res) {
                    layer.msg(res.message, {time: 2000}, function () {
                        location.href="/agentUser/index/${user.agentId}";
                    });
                }
            });
        });
    </script>
</#assign>
<@layout title="角色分配" active="agentUser">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            角色分配
            <small>分配管理员关联角色</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
            <li><a href="/agent/index"><i class="fa fa-list-ul"></i> 分站管理</a></li>
            <li><a href="/agentUser/index/${user.agentId}"><i class="fa fa-list-ul"></i> 分站管理员管理</a></li>
            <li class="active"><i class="fa fa-edit"></i> 角色分配</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- Default box -->
                <div class="box  box-primary">


                    <#if user.userId==1>


                        <div class="box-body text-center" style="padding:50px 10px;">
                            该账号为默认超级管理员，不能分配其他角色！
                        </div>
                        <div class="box-footer">
                            <button type="button" class="btn btn-info pull-right btn-back">返回</button>
                        </div>


                    <#else>

                        <form class="form-horizontal form-grant" method="post" action="/agentUser/grant">
                            <div class="box-body">
                                <input type="hidden" id="userId" name="userId" value="${user.userId}">
                                <div class="form-group">
                                    <#list roles as role>
                                        <div class="col-sm-12">
                                            <div class="checkbox i-checks">
                                                <label>
                                                    <#if roleIds?seq_contains(role.roleId?string)>
                                                        <input type="checkbox" value="${role.roleId}" name="roleIds"
                                                               checked="checked"> <i></i> ${role.roleName}
                                                    <#else>
                                                        <input type="checkbox" value="${role.roleId}" name="roleIds">
                                                        <i></i> ${role.roleName}
                                                    </#if>
                                                </label>
                                            </div>
                                        </div>
                                    </#list>
                                </div>
                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn btn-default btn-back">返回</button>
                                <button type="button" class="btn btn-info pull-right btn-submit">提交</button>
                            </div>
                        </form>
                    </#if>


                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</@layout>